package com.vichat.common.util;

import org.apache.commons.lang3.StringUtils;

import java.io.StringReader;
import java.util.Properties;

/**
 * Created by wangluyin on 2017/3/7.
 */
public class StringToPropertiesConverter {
    public static  Properties convert(String source) {
        if(source == null) {
            return null;
        } else {
            Properties info = new Properties();
            StringReader stringReader = new StringReader(source);

            try {
                info.load(stringReader);
            } catch (Exception var8) {
                var8.printStackTrace();
            } finally {
                stringReader.close();
            }

            return info;
        }
    }

    public static void  main(String[] args){
        String[] strs = StringUtils.split("state=1,type=sgs,id=1014,snd=10,ack=10;state=1,type=ims,id=1013,snd=10,ack=10;",";");
        for (String str:strs
             ) {
            Properties properties = StringToPropertiesConverter.convert(str.replaceAll(",","\n"));
            System.out.println(properties.getProperty("state"));
            System.out.println(properties.getProperty("type"));
            System.out.println(properties.getProperty("id"));
            System.out.println(properties.getProperty("snd"));
            System.out.println(properties.getProperty("ack"));
        }

    }
}
